/************************
*
*		VCMAPI.h		:	v0010
*		v0010			:	Mar.26.1997
*		Origenal from	:	Intel
*		Changed by		:	Liu Gang
*		Copyright		:	WayAhead Software Co., Ltd
*
*
*		included:	Assert.h
*					Vfw_spec.h
*					Datatype.h
*					Videovcm.h
*					Dib.h
*					Avimovie.h
*					Scale.h
*					Movie.h				
*************************/

/************************/
/***
*assert.h - define the assert macro
*
*	Copyright (c) 1985-1995, Microsoft Corporation. All rights reserved.
*
*Purpose:
*	Defines the assert(exp) macro.
*	[ANSI/System V]
*
*       [Public]
*
****/

#if !defined(_WIN32) && !defined(_MAC)
#error ERROR: Only Mac or Win32 targets supported!
#endif



/* Define _CRTAPI1 (for compatibility with the NT SDK) */

#ifndef _CRTAPI1
#if	_MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI1 __cdecl
#else
#define _CRTAPI1
#endif
#endif


/* Define _CRTAPI2 (for compatibility with the NT SDK) */

#ifndef _CRTAPI2
#if	_MSC_VER >= 800 && _M_IX86 >= 300
#define _CRTAPI2 __cdecl
#else
#define _CRTAPI2
#endif
#endif


/* Define _CRTIMP */

#ifndef _CRTIMP
#ifdef	_NTSDK
/* definition compatible with NT SDK */
#define _CRTIMP
#else	/* ndef _NTSDK */
/* current definition */
#ifdef	_DLL
#define _CRTIMP __declspec(dllimport)
#else	/* ndef _DLL */
#define _CRTIMP
#endif	/* _DLL */
#endif	/* _NTSDK */
#endif	/* _CRTIMP */


/* Define __cdecl for non-Microsoft compilers */

#if	( !defined(_MSC_VER) && !defined(__cdecl) )
#define __cdecl
#endif


#undef	assert

#ifdef TNDEBUG

#define assert(exp)	((void)0)

#else

#ifdef __cplusplus
extern "C" {
#endif

_CRTIMP void __cdecl _assert(void *, void *, unsigned);

#ifdef __cplusplus
}
#endif

#define assert(exp) (void)( (exp) || (_assert(#exp, __FILE__, __LINE__), 0) )

#endif	/* NDEBUG */
/************************/



/************************************************************************
*  vfw_spec.h                                                           *
*                                                                       *
* This code and information is provided "as is" without warranty of     *
* any kind, either expressed or implied, including but not limited to	*
* the implied warranties of merchantability and/or fitness for a        *
* particular purpose.                                                   *
*                                                                       *
*               Copyright (c) 1994-1995 Intel Corporation.              *
*                         All Rights Reserved.                          *
*                                                                       *
************************************************************************/
/*
 *
 *  DESCRIPTION:
 *  The Indeo(R) Video Interactive codec provides access to new features
 *  using the ICM_SETCODECSTATE and ICM_GETCODECSTATE messages. This header
 *  file defines the data structures used in these messages.
 */

/* $Revision:   1.27  $
 */


#ifndef __VFW_SPEC_H__
#define __VFW_SPEC_H__


/* The specific interface version is defined as follows:
 */
#define INTERFACE_MAJOR_NUMBER(v)		((v) >> 16)
#define INTERFACE_MINOR_NUMBER(v)		((v) & 0xffff)
#define CREATE_INTERFACE_VERSION(maj,min)	((((DWORD)maj)<<16) | (((DWORD)min) & 0xffff))
#define SPECIFIC_INTERFACE_VERSION 		CREATE_INTERFACE_VERSION(1,2)

/* The codec specific information is handled by the general state
 * handler.
 */
#define ICM_GETCODECSTATE					ICM_GETSTATE
#define ICM_SETCODECSTATE					ICM_SETSTATE
#define	EXTENDED_INTERFACE_SIZE				1

/* OS Environments - Within the Microsoft Windows domain (Win 3.1, Win 95,
 * and Win NT), both applications and codecs can be compiled in either 16 or
 * 32-bit formats.  Any combination is allowed with the knowledge that data
 * pointers will not be thunked.
 */
typedef enum {
	OE_UNDEFINED,
	OE_16,
	OE_32,
} R4_OS_ENVIRONMENT;


/* The type field identifies the kind of operation that should be done as part
 * of the ICM_GETCODECSTATE and ICM_SETCODECSTATE messages.
 *
 * The MT_UNDEFINED value is not a supported type - it should only be used
 * to initialize variables to an "undefined" state.
 */
typedef enum {
	MT_UNDEFINED,
	MT_DECODE_FRAME_DEFAULT,
	MT_DECODE_FRAME_VALUE,
	MT_DECODE_SEQ_DEFAULT,
	MT_DECODE_SEQ_VALUE,
	MT_ENCODE_SEQ_DEFAULT,
	MT_ENCODE_SEQ_VALUE,
	MT_DECODE_INIT_DATA
} R4_MESSAGE_TYPE;

/*
 * MT_QUEUE is for 16-bit applications that call 32-bit codecs, only.  It
 * is necessary to pre-set ICM_GETCODECSTATE messages by first issuing an
 * ICM_SETCODECSTATE with the MT_QUEUE flag or'ed with the desired
 * message type to get.  The ICM_GETCODECSTATE message which follows
 * must set its dwFourCC field to 0.
 */
#define	MT_QUEUE  (1UL<<31)

/* UCHAR is defined in Win32 but not Win16 MS* Windows headers.
 */
#if !defined UCHAR
typedef unsigned char UCHAR;
#endif

/* A flag is false if it is zero, otherwise it is true.
 */
typedef DWORD R4_FLAG;

/* Pointer to a Flag - A pointer to a flag is used by the codec to write 
 * status information at a later time.
 */
typedef R4_FLAG FAR * PTR_R4_FLAG;
 

/* Rectangle - The following structure is used to describe a rectangle.
 */
typedef struct {
	DWORD dwX;
	DWORD dwY;
	DWORD dwWidth;
	DWORD dwHeight;
} R4_RECT, FAR * PTR_R4_RECT;


/* Transparency Bitmask - A transparency bitmask contains one bit for each 
 * pixel in the source image. If a bit is zero the data is transparent.  
 * The first bit in each byte is identified by the mask 0x80.  The last 
 * bit in each byte is identified by the mask 0x01. 
 * 
 * To allow faster access each row must begin on a DWORD boundary and the 
 * total number of bytes must be rounded-up to a multipe of four.
 */
typedef BYTE FAR * PTR_R4_BITMASK;


/* Playback Platform - The codec supports several playback options.  This is
 * not hardware specific.  Instead it rates the relative capabilities of the  
 * hardware.
 */
typedef enum {
	PP_LOW,
	PP_MEDIUM,
	PP_HIGH,
} R4_PLAYBACK_PLATFORM;


/* Transparency Method - The codec supports a number of tranparency encoding
 * methods. The enumeration specifies the transparency method.
 */
typedef enum {
	TM_UNDEFINED,
	TM_NONE,
	TM_RANGE,
	TM_BITMASK,
	TM_FRAME,
	TM_ALPHA_CHANNEL		/* XRGB color formats only */
} R4_TRANS_METHOD;


/* Transparency Range - A transparency range is specified using minimum 
 * and maximum values for R, G, and B. Any pixel with values within this range 
 * (inclusive) is considered transparent.
 */
typedef struct {
	WORD		u16Reserved;
	UCHAR		u8BlueLow;
	UCHAR		u8BlueHigh;
	UCHAR		u8GreenLow;
	UCHAR		u8GreenHigh;
	UCHAR		u8RedLow;
	UCHAR		u8RedHigh;
} R4_RANGE, FAR * PTR_R4_RANGE;


/* The structure header is a set fields that are common,
 * to each of the data structures that follows.
 */
typedef struct {
	DWORD		dwSize;
	DWORD		dwFourCC;
	DWORD		dwVersion;
	LONG		mtType;	
	LONG		oeEnvironment;
	DWORD		dwFlags;
} R4_HEADER, FAR * PTR_R4_HEADER;
/* The structure header size is enough room for dwSize, dwFourCC,
 * dwVersion, dwType, dwEnvironment, and dwFlags
 */
#define R4_STRUCTURE_HEADER_SIZE (sizeof(R4_HEADER))


typedef enum {
	OFF,
	LOW,
	MEDIUM,
	HIGH
} R4_DITHER;

/* Some decode parameters can be changed prior to either an ICM_DECOMPRESS or 
 * ICM_DECOMPRESSEX mesage. These are found in the  R4_DEC_FRAME_DATA 
 * structure.  See CUSTOM_INTERFACE_ENCODER_DATA for structure size constraints.
 */
#define DECFRAME_TIME_LIMIT				(1UL<<0)
#define DECFRAME_DECODE_RECT				(1UL<<1)
#define DECFRAME_VIEW_RECT				(1UL<<2)
#define DECFRAME_BOUNDING_RECT			(1UL<<3)
#define DECFRAME_TRANS_BITMASK			(1UL<<4)
#define DECFRAME_BRIGHTNESS				(1UL<<5)
#define DECFRAME_SATURATION				(1UL<<6)
#define DECFRAME_CONTRAST				(1UL<<7)
#define DECFRAME_FILL_COLOR				(1UL<<9)
#define DECFRAME_8BIT_CONFIG_PALETTE		(1UL<<10)
#define DECFRAME_8BIT_DITHER				(1UL<<11)
#define DECFRAME_VIEW_RECT_ORIGIN			(1UL<<12)
#define DECFRAME_INPUT_TRANS_MASK			(1UL<<13)
#define DECFRAME_VALID					(1UL<<31)

/* Signals that the fill color provided is not a defined value */
#define DECFRAME_FILL_UNDEFINED 0xFF000000

typedef struct {
	DWORD			dwSize;
	DWORD			dwFourCC;
	DWORD			dwVersion;
	LONG			mtType;	
	LONG			oeEnvironment;
	DWORD			dwFlags;

	DWORD			dwTimeLimit;				/* version 1.0 */
	R4_RECT		rDecodeRect;				/* version 1.0 */
	R4_RECT		rViewRect;					/* version 1.0 */
	PTR_R4_RECT 	prBoundingRect;				/* version 1.0 */
	PTR_R4_BITMASK 	pbmTransparencyBitmask;			/* version 1.0 */
	PTR_R4_FLAG 	pfUpdatedTransparencyBitmask;		/* version 1.0 */
	LONG			lBrightness;				/* version 1.0 */
	LONG			lSaturation;				/* version 1.0 */
	LONG			lContrast;					/* version 1.0 */
	
	DWORD			dwFillColor;				/* version 1.2 */
	DWORD			dwFirstPalIndex;				/* version 1.2 */
	DWORD			dwLastPalIndex;				/* version 1.2 */
	LPRGBQUAD		prgbPalette;				/* version 1.2 */
	R4_DITHER		eDither;					/* version 1.2 */
	R4_FLAG		fViewRectOrigin;				/* version 1.2 */
	PTR_R4_BITMASK 	pbmInputTransparencyBitmask;		/* version 1.2 */
} R4_DEC_FRAME_DATA, FAR * PTR_R4_DEC_FRAME_DATA;

/* Turning scalability off completely was accomplished in versions 1.0 and 1.1
 * of the interface by decoding in STEPPING mode.  Setting the scalability
 * flag to false meant not to drop the quality of frames, but frames could
 * still be dropped.  For this reason, if SC_OFF is used, it will map to 
 * stepping mode, and SC_DONT_DROP_QUALITY occupies the position of "false."
 */
typedef enum {
	SC_DONT_DROP_QUALITY,
	SC_ON,
	SC_DONT_DROP_FRAMES,
	SC_OFF,
} R4_SCALABILITY;

/* Other decode parameters can only be changed prior to either an 
 * ICM_DECOMPRESS_BEGIN or an ICM_DECOMPRESSEX_BEGIN message.  These 
 * are found in the R4_DEC_SEQ_DATA structure.
 * See CUSTOM_INTERFACE_ENCODER_DATA for structure size constraints.
 */ 
#define DECSEQ_KEY				(1UL<<0)
#define DECSEQ_SCALABILITY			(1UL<<1)
#define DECSEQ_FILL_TRANSPARENT		(1UL<<2)
#define DECSEQ_ALT_LINE				(1UL<<3)
#define DECSEQ_VALID 				(1UL<<31)

typedef struct {
	DWORD		dwSize;
	DWORD		dwFourCC;
	DWORD		dwVersion;
	LONG		mtType;	
	LONG		oeEnvironment;
	DWORD		dwFlags;

	DWORD		dwKey;					/* version 1.0 */
	R4_FLAG		fEnabledKey;			/* version 1.0 */
	LONG		eScalability;				/* version 1.2; 1.0 fScalability */
	R4_FLAG		fFillTransparentPixels;		/* version 1.0 */
	R4_FLAG		fAltLine;				/* version 1.1 */
} R4_DEC_SEQ_DATA, FAR * PTR_R4_DEC_SEQ_DATA;


/* Decode persistent data parameters can only be sent prior to the
 * first ICM_DECOMPRESS_BEGIN message. These are found in the
 * R4_DECODE_INIT_DATA structure.
 */
#define DECINIT_VALID				(3UL<<30)	/* valid bit + one other bit */

typedef struct {
	DWORD		dwSize;
	DWORD		dwFourCC;
	DWORD		dwVersion;
	LONG		mtType;	
	LONG		oeEnvironment;
	DWORD		dwFlags;

	R4_FLAG	fBidir;					/* version 1.2 */
	R4_FLAG	fDeltaFrames;				/* version 1.2 */
	R4_FLAG	fTransparency;				/* version 1.2 */
	DWORD		dwNLevels;					/* version 1.2 */
	DWORD		dwTileWidth;				/* version 1.2 */
	DWORD		dwTileHeight;				/* version 1.2 */
} R4_DECODE_INIT_DATA, FAR * PTR_R4_DECODE_INIT_DATA;


/* Encode parameters can only be changed prior to an ICM_COMPRESS_BEGIN 
 * messsage.  These are found in the R4_ENC_SEQ_DATA structure (these 
 * include the parameters that can be set in the super dialog box).
 * See CUSTOM_INTERFACE_ENCODER_DATA for structure size constraints.
 */  
#define ENCSEQ_KEY				(1UL<<0)
#define ENCSEQ_MINIMUM_VIEWPORT		(1UL<<1)
#define ENCSEQ_TRANSPARENCY			(1UL<<2)
#define ENCSEQ_SCALABILITY			(1UL<<3)
#define ENCSEQ_BI_DIR_PREDICTION		(1UL<<4)
#define ENCSEQ_PLAYBACK_PLATFORM		(1UL<<5)
#define ENCSEQ_RANDOM_KEY_AND_BIDIR 	(1UL<<6)
#define ENCSEQ_FRAME_INFO			(1UL<<7)
#define ENCSEQ_QUICK_COMPRESS			(1UL<<8)
#define ENCSEQ_VALID				(1UL<<31)

typedef struct {
	DWORD			dwSize;
	DWORD			dwFourCC;
	DWORD			dwVersion;
	LONG			mtType;	
	LONG			oeEnvironment;
	DWORD			dwFlags;

	DWORD			dwKey;					/* version 1.0 */
	DWORD			dwMinViewportWidth;			/* version 1.0 */
	DWORD			dwMinViewportHeight;			/* version 1.0 */
	R4_RANGE		rngTransparencyRange;			/* version 1.0 */
	PTR_R4_BITMASK 	pbmTransparencyBitmask;			/* version 1.0 */
	LONG			tmTransparencyMethod;			/* version 1.0 */
	R4_FLAG		fEnabledKey;				/* version 1.0 */
	R4_FLAG		fScalability;				/* version 1.0 */
	R4_FLAG		fBiDirPrediction;				/* version 1.0 */
	R4_FLAG		fRandomKeyAndBiDir;			/* version 1.0 */
	DWORD			dwPlaybackPlatform;			/* version 1.0 */
	WORD			wFrameLatency;				/* version 1.0 */
	WORD			wDeadFrames;				/* version 1.0 */
	R4_FLAG		fQuickCompress;				/* version 1.1 */
} R4_ENC_SEQ_DATA, FAR * PTR_R4_ENC_SEQ_DATA;


#endif /* __VFW_SPEC_H__ */
/************************/


/************************************************************************
*  datatype.h                                                           *
*                                                                       *
* This code and information is provided "as is" without warranty of     *
* any kind, either expressed or implied, including but not limited to   *
* the implied warranties of merchantability and/or fitness for a        *
* particular purpose.                                                   *
*                                                                       *
*               Copyright (c) 1994-1995 Intel Corporation.              *
*                         All Rights Reserved.                          *
*                                                                       *
************************************************************************/

#ifndef __DATATYPE_H__
#define __DATATYPE_H__

#include <stddef.h>
/* These are the non platform specific data types
 * for which all data and return types are defined
 */

/* These types of data must allways be the same
 * number of bits regardless of the platform.
 * Therefore, these generic names are defined
 * to be:
 * 
 * U8      8 bits,  unsigned 0..255
 * I8      8 bits,  signed -128..127
 * U16     16 bits, unsigned 0..65535
 * I16     16 bits, signed -32768..32767
 * U32     32 bits, unsigned 0..4294967295
 * I32     32 bits, signed -2147483648..2147483647
 * Sngl    32 bit floating point (4 bytes)
 * Dbl     64 bit floating point (8 bytes)
 * 
 * These pointers are naturally platform specific,
 * but what they point to is allways the same size
 *
 *               These are huge pointers
 * PU8
 * PI8
 * PU16
 * PI16
 * PU32
 * PI32
 * PSngl
 * PDbl
 *               These are far pointers
 * FPU8
 * FPI8
 * FPU16
 * FPI16
 * FPU32
 * FPI32
 * FPSngl
 * FPDbl
 */

#if defined HUGE
#undef HUGE
#endif
#if defined FAR
#undef FAR
#endif
#if defined NEAR
#undef NEAR
#endif

#if defined WINDOWS
#if defined WIN32
/* WINDOWS NT data types, Only X86 support at this time */
#define NEAR
#define FAR
#define HUGE

// TCHAR should be appropriately defined in std header files - ??
// #ifndef _TCHAR_DEFINED
// typedef wchar_t TCHAR; /* unicode for strings */
// #endif

typedef unsigned char  U8;
typedef signed char    I8;
typedef unsigned short U16;
typedef signed short   I16;
typedef unsigned long  U32;
typedef signed long    I32;
typedef float          Sngl;
typedef double         Dbl;

#else /* WIN32 not defined */
/* WINDOWS 3.x under DOS data types */
#define NEAR _near
#define FAR  _far
#define HUGE _huge

#ifndef _INC_TCHAR
typedef char far *			LPTSTR;
typedef const char far *	LPCTSTR;
typedef char				TCHAR;
#define TEXT(quote)			quote
#endif
#ifndef BOOLEAN
typedef char BOOLEAN;
#endif
#ifndef INT
typedef int INT;
#endif

typedef unsigned char  U8;
typedef signed char    I8;
typedef unsigned short U16;
typedef signed short   I16;
typedef unsigned long  U32;
typedef signed long    I32;
typedef float          Sngl;
typedef double         Dbl;

#endif /* WIN32 */
#else /* WINDOWS not defined */
/* UNIX data types */
#define NEAR
#define FAR
#define HUGE
#define CDECL
#define BSENC 1
#define HGLOBAL PI16
#define LRESULT I32
//#define HINSTANCE PU8 // Currently defined elsewhere

typedef char TCHAR; /* for compatability with win/win32 datatypes for strings */

typedef unsigned char    U8;
typedef signed char      I8;
typedef unsigned short   U16;
typedef signed short int I16;
typedef unsigned long    U32;
typedef signed long      I32;
typedef float            Sngl;
typedef double           Dbl;

/* move WIN32 UNICODE data types to UNIX data types */
typedef char * LPTSTR;
typedef const char * LPCTSTR;

#ifndef TEXT
#define TEXT(quote) quote
#endif /* TEXT */
#endif /* WINDOWS */

typedef char Chr;        /* character string */
typedef char Qchar;  /* quoted character string */

/* pointers */
typedef Chr  NEAR * PChr;       /* near pointer to Character string */
typedef U8   NEAR * PU8;        /* near pointer to unsigned char */
typedef I8   NEAR * PI8;        /* near pointer to signed char */
typedef U16  NEAR * PU16;       /* near pointer to unsigned 16 bit value */
typedef I16  NEAR * PI16;       /* near pointer to signed 16 bit value */
typedef U32  NEAR * PU32;       /* near pointer to unsigned 32 bit value */
typedef I32  NEAR * PI32;       /* near pointer to signed 32 bit value */
typedef Sngl NEAR * PSngl;      /* near pointer to single precision float */
typedef Dbl  NEAR * PDbl;       /* near pointer to double precision float */

typedef Chr  FAR * FPChr;       /* far pointer to Character string */
typedef U8   FAR * FPU8;        /* far pointer to unsigned char */
typedef I8   FAR * FPI8;        /* far pointer to signed char */
typedef U16  FAR * FPU16;       /* far pointer to unsigned 16 bit value */
typedef I16  FAR * FPI16;       /* far pointer to signed 16 bit value */
typedef U32  FAR * FPU32;       /* far pointer to unsigned 32 bit value */
typedef I32  FAR * FPI32;       /* far pointer to signed 32 bit value */
typedef Sngl FAR * FPSngl;      /* far pointer to single precision float */
typedef Dbl  FAR * FPDbl;       /* far pointer to double precision float */

typedef Chr  HUGE * HPChr;      /* huge pointer to Character string */
typedef U8   HUGE * HPU8;       /* huge pointer to unsigned char */
typedef I8   HUGE * HPI8;       /* huge pointer to signed char */
typedef U16  HUGE * HPU16;      /* huge pointer to unsigned 16 bit value */
typedef I16  HUGE * HPI16;      /* huge pointer to signed 16 bit value */
typedef U32  HUGE * HPU32;      /* huge pointer to unsigned 32 bit value */
typedef I32  HUGE * HPI32;      /* huge pointer to signed 32 bit value */
typedef Sngl HUGE * HPSngl;     /* huge pointer to single precision float */
typedef Dbl  HUGE * HPDbl;      /* huge pointer to double precision float */

typedef PU8  NEAR * PPU8;        /* near handle to unsigned char */
typedef PI8  NEAR * PPI8;        /* near handle to unsigned char */
typedef PU16  NEAR * PPU16;        /* near handle to unsigned char */
typedef PI16  NEAR * PPI16;        /* near handle to unsigned char */
typedef PU32  NEAR * PPU32;        /* near handle to unsigned char */
typedef PI32  NEAR * PPI32;        /* near handle to unsigned char */

/* These types of data do not need to be the
 * same from platform to platform. The only
 * concern is that the values represented by
 * these types fit into the smallest bit size
 * of any platform we port to. As new platforms
 * are added, please update this table:
 * 
 *                  WIN3.x UNIX  WINNT (win32)
 * NaturalInt:      16     32    32
 * NaturalUnsigned: 16     32    32
 * 
 * These pointers are naturally platform specific,
 * and what they point to is allowed to be
 * platform specific also
 *
 *               These are huge pointers
 * PNaturalInt
 * PNaturalUnsigned
 *               These are far pointers
 * FPNaturalInt
 * FPNaturalUnsigned
 *
 * For those who complain about long identifiers,
 * these data types are spelled out specifically
 * to avoid confusion with the fixed length data
 * types and to let the reader who is unfamiliar
 * with our coding practices know that these data
 * types are different on each platform. The intent
 * is to be obvious and obnoxious.
 *
 * to facilitate testing, define TEST_16_BITS
 * which will force all natural data types to 16 bits
 */

#if defined TEST_16_BITS
typedef I16 NaturalInt;
typedef U16 NaturalUnsigned;
#else
#if defined TEST_32_BITS
typedef I32 NaturalInt;
typedef U32 NaturalUnsigned;
#else
typedef signed int NaturalInt;
typedef unsigned int NaturalUnsigned;
#endif /* TEST_32_BITS */
#endif /* TEST_16_BITS */

/* pointers */
typedef NaturalInt HUGE *      PNaturalInt;
typedef NaturalUnsigned HUGE * PNaturalUnsigned;

typedef NaturalInt FAR *       FPNaturalInt;
typedef NaturalUnsigned FAR *  FPNaturalUnsigned;

/* logical types */
typedef NaturalInt		Boo;    /* was U32 */
typedef Boo				Boolean;
typedef Boo*			pBoo;

/* BGR_ENTRY
 * The BGR_ENTRY structure is used to define one color.
 */
typedef struct {
	U8 u8B;
	U8 u8G;
	U8 u8R;
	U8 u8Reserved;
} BGR_ENTRY;
typedef BGR_ENTRY FAR * PTR_BGR_ENTRY;

/* ASM interface */
#if defined WIN32
#define ASM_CALLTYPE _stdcall
#else
#define ASM_CALLTYPE
#endif

typedef void NEAR * LOCAL_HANDLE;
typedef void NEAR * GLOBAL_HANDLE;
typedef void NEAR * VOID_LOCAL_PTR;
typedef void FAR * VOID_GLOBAL_PTR;  
typedef void HUGE * VOID_HUGE_PTR;  
typedef void NEAR * MUTEX_HANDLE;
typedef void NEAR * VOID_INSTANCE_PTR;

#define PChr	PU8
#define TRUE  1
#define FALSE 0

#endif /* __DATATYPE_H__ */
/************************/

/************************/
// DIB.H
//
// Portions (almost all) taken from Nigel Thompson's "Animation techniques in Win32"
//
// Created:		10/27/95
//

#ifndef _DIB_H_
#define _DIB_H_


class DIB {
public:
	DIB();
	~DIB();

	BITMAPINFO* GetBitmapInfoAddress()
		{return m_pBMI;}
	BYTE* GetBitsAddress()
		{return m_pBits;}
	RGBQUAD* GetClrTabAddress()
        {return (m_pBMI->bmiHeader.biBitCount <= 8) ? (LPRGBQUAD)(((BYTE*)(m_pBMI)) 
            + sizeof(BITMAPINFOHEADER)) : NULL;}       // Pointer to color table
	int GetNumClrEntries();


   BOOL Create(BITMAPINFO* pBMI, BYTE* pBits); // Create from existing mem
	BOOL Create(int width, int height, int iBpp = 8);

   void* GetPixelAddress(int x, int y);
	virtual BOOL Load(HWND hwnd, LPCSTR lpszFileName, int bpp);
   virtual int GetWidth() {return DibWidth();}   // Image width
   virtual int GetHeight() {return DibHeight();} // Image height
	virtual BOOL MapColorsToPalette(HPALETTE hPal);
   virtual void GetRect(RECT* pRect);
   virtual void CopyBits(DIB* pDIB, 
                         int xd, int yd,
                         int w,  int h,
                         int xs, int ys);
   inline int GetBitDepth( void )
      {return m_pBMI->bmiHeader.biBitCount;}


protected:
	BITMAPINFO* m_pBMI;
	BYTE* m_pBits;
   BOOL  m_bMyBits;  // TRUE if DIB owns bits

private:
	int DibWidth()
		{return m_pBMI->bmiHeader.biWidth;}
	int DibHeight()
		{return m_pBMI->bmiHeader.biHeight;}
   int StorageWidth()
      {return (m_pBMI->bmiHeader.biWidth * 
        		 m_pBMI->bmiHeader.biBitCount / 8 + 3) & ~3;}

};

#endif // _DIB_H
/************************/

/************************/
// videoVCM.h : Interface of the CVideoVCM class
//

// This code and information is provided "as is" without warranty of
// any kind, either expressed or implied, including but not limited to
// the implied warranties of merchantability and/or fitness for a
// particular purpose.

// Copyright (C) 1995 Intel Corporation.  All rights reserved.
//

#ifndef _AVIVCM_H_
#define _AVIVCM_H_

#define OLE2ANSI
#include <vfw.h>
#undef OLE2ANSI

#define ALIGNULONG(bytes) ((((bytes) + 3) / 4) * 4)

// For Indeo(R) Video Interactive specific routines
//#include "datatype.h"
//#include "vfw_spec.h"

// DIB stuff
//#include "dib.h"

#define FOURCC_iv41 mmioFOURCC('i','v','4','1')
#define FOURCC_IV41 mmioFOURCC('I','V','4','1')

// Error codes

#define VCMERR_OK		0L
#define VCMERR_INTERNAL		-1L

///////////////////////////////////////////////////////////////////////////////
// CVideoVCM Defininition

class CVideoVCM
{
public:
	CVideoVCM ();
	~CVideoVCM ();

// Operations

   long  vcmOpen (FOURCC fccHandler, BITMAPINFOHEADER * pbiSrc);	
	long	vcmClose ();

	long	vcmBegin (HDC hdc, float frate);
	long	vcmEnd ();

	long	vcmDrawStart (float frate);
	long	vcmDrawStop ();

	long	vcmDraw (unsigned char * pbits, DWORD dwICflags = 0L);
	long	vcmDrawIn (unsigned char *pbits, DWORD dwICflags = 0L);

	inline FOURCC vcmGetFOURCC () { return m_fccHandler; }

// Handles

	HIC		m_hic;
	HDC		m_hdc;
	HDRAWDIB	m_hdd;

	FOURCC		m_fccHandler;

// Information

	void vcmGetSrcRect (RECT * rect);
	void vcmSetSrcRect (RECT * rect);
	void vcmGetDestRect (RECT * rect);
	void vcmSetDestRect (RECT * rect);
	void vcmGetOutRect (RECT * rect);
	void vcmSetOutRect (RECT * rect);
	void vcmGetWndRect (RECT * rect);
   long vcmGetBoundRect(RECT * rect);

	void vcmGetSrcBi (BITMAPINFOHEADER * pbiSrc);
	void vcmSetSrcBi (BITMAPINFOHEADER * pbiSrc);
	void vcmGetDestBi (BITMAPINFOHEADER * pbiDst);
	void vcmSetDestBi (BITMAPINFOHEADER * pbiDst);
	
	long vcmQueryDest (BITMAPINFOHEADER * pbiDst,
	                   int x = 0, int y = 0, int dx = 0, int dy = 0);

// Indeo(R) Video Interactive operations

	void vcmGetBSC (long *bval, long *sval, long *cval, BOOL fDefault); // -255 to +255
	void vcmSetBSC (long bval, long sval, long cval, BOOL fDefault);    // -255 to +255
	void vcmGetScalability (float frate, int *cpu_percentage, BOOL fDefault);
	void vcmSetScalability (float frate, int cpu_percentage, BOOL fDefault);
   BOOL vcmSetZoomMode(int altMode, BOOL fDefault);
   BOOL vcmSetPalette(LOGPALETTE* pLogPal);
   BOOL vcmSetBackground(DIB* pDIB);

	void vcmSetAccessKey(DWORD dwKey);
   BOOL vcmSet8BitDitherPalette( int dither, int iFirst, int iLast );
   BOOL vcmGet8BitDither( int* dither );


protected:
	BOOL	m_bBegun;
	// Source, Destination, and Output
	BITMAPINFOHEADER * m_pbiSrc;
	BITMAPINFOHEADER * m_pbiDst;

	long	m_xsrc, m_ysrc, m_dxsrc, m_dysrc;
	long	m_xdst, m_ydst, m_dxdst, m_dydst;
	long	m_xout, m_yout, m_dxout, m_dyout;
	long	m_xwnd, m_ywnd, m_dxwnd, m_dywnd;

	// Indeo(R) Video Interactive specific structures
	R4_DEC_SEQ_DATA   m_r4seqCurrent, m_r4seqDefault;
	R4_DEC_FRAME_DATA m_r4frameCurrent, m_r4frameDefault;

   // bounding rectangles for transparencies   
   R4_RECT m_r4BR;  
   R4_RECT m_r4LastBR;  

   // DIBs for transparency background
   DIB* m_pDIB;
   DIB* m_pBG;
	
	// DIB Section
	HBITMAP m_hDIBSection;
	unsigned char * m_pDIBSection;
public:
	HPALETTE	m_hpalSection;

private:
	
	// Temporary buffer used internally
	int		m_cbuf;
	unsigned char *	m_pbuf;

	HDC		m_hmemDC;
	HBITMAP		m_hbmOld;
	HPALETTE	m_hpalOld_DC, m_hpalOld_MemDC;
};

#endif // _AVIVCM_H_
/************************/

/************************/

// aviMovie.h : Interface of the CAviMovie class
//

// This code and information is provided "as is" without warranty of
// any kind, either expressed or implied, including but not limited to
// the implied warranties of merchantability and/or fitness for a
// particular purpose.

// Copyright (C) 1995 Intel Corporation.  All rights reserved.
//

#ifndef _AVIMOVIE_H_
#define _AVIMOVIE_H_

#define OLE2ANSI
#include <vfw.h>
#undef OLE2ANSI

// Since we need VCM services
//#include "videoVCM.h"
// and DIBs
//#include "dib.h"

///////////////////////////////////////////////////////////////////////////////
//

// Messages
#define AVIMOV_NOTIFYSIZE	(WM_USER+1) // tell parent to resize

// Maximum # streams open at once
#define MAXSTREAMS 16

// Maximum frames of audio skew
#define MAX_AUDIOBUFS 32

// Error codes
#define MOVERR_OK				0L
#define MOVERR_NOVIDEOSTREAM 	-1L
#define MOVERR_VIDS				-2L
#define MOVERR_AUDS				-3L
#define MOVERR_PLAYING			-4L
#define MOVERR_BADOPTION		-5L

#define AUDSERR_OK				0L
#define AUDSERR_NOAUDIO			-10L
#define AUDSERR_MAXBUFSEXCEEDED	-11L
#define AUDSERR_UNSUPPORTEDFORMAT -12L
#define AUDSERR_OPEN			-13L
#define AUDSERR_WAVEOUT			-14L

#define VIDSERR_OK				0L
#define VIDSERR_NOVIDEO			-20L
#define VIDSERR_VCM				-21L
#define VIDSERR_DC				-22L
#define VIDSERR_NOTSTARTED		-23L
#define VIDSERR_READ			-24L

///////////////////////////////////////////////////////////////////////////////
// CAviV Defininition

class CAviMovie
{
public:
	CAviMovie ();
	~CAviMovie ();

// VCM
// WARNING: should only access VCM during stopped mode (for accesses that will
//  change the state).
	CVideoVCM * m_pVCM;

   DIB* m_pDIB;

// Avi File
	// Operations
public:
	long	FileOpen (LPCTSTR lpszPathName);
	long	FileClose ();

	// Information
	PAVIFILE	m_pfile;
	PAVISTREAM	m_paviVideo;	// video stream to play
	PAVISTREAM	m_paviAudio;	// audio stream to play

// Movie
	// Operations
public:
	HWND	m_hwnd;

	long	MovieOpen (HWND hwnd);
	long	MovieClose ();

	long	MovieStart (HDC hdc);
	long	MovieStop ();
	long	MoviePause ();

	long	MovieSeek (long lpos);         // absolute seek from beginning of file
	long	MovieSeekCurrent (long ldiff); // relative seek from current pointer

		// Set destination options, i.e. resolution and/or bpp
	long	MovieSetDestOptions (float zoom, int bpp = 0, int altMode = 0, long xres = 0, long yres = 0);
   long  MovieSetDestPalette (LOGPALETTE* pLogPal);
   long  MovieSet8BitDither( int dither, int iFirst, int iLast );
   long  MovieGet8BitDither( void );

   long  MovieSetBackground (char * lpszBmpName);

		// Miscellaneous queries
	BOOL	MovieIsFileOpen () { return (m_pfile != 0); }
	BOOL	MovieIsPlaying () { return (m_bPlaying); }
	BOOL	MovieIsEnd () { return (m_vidsCurrent == m_vidsLast); }

	UINT	MovieGetTimeslice () { return (UINT) (1.0/m_frate*1000.0); }
	float	MovieGetFrameRate () { return m_frate; }

	// Information
protected:
	BOOL	m_bPlaying;	// F if stopped/paused
	BOOL	m_bPaused;      // T if paused
	
		// These are the same for now, can change the frate for faster/slower playback
	float	m_fps;          // frame rate of file
	float	m_frate;        // frame rate of playback

	// Syncronization
public:
	long	vidsTimeToSample (long lTime);
	long	vidsSampleToTime (long lSample);
private:
	UINT	m_resolution;   // minimum timing resolution for current machine

// Video
	// Operations
public:
	long	vidsVideoOpen ();
	long	vidsVideoClose ();

		// These functions can change state of m_bPlaying.
	long	vidsVideoStart (HDC hdc, long fStart = -1L);
	long	vidsVideoStop ();
	
	long	vidsVideoDraw ();
	
	long	vidsGetTime () { return ((long) (float(m_vidsCurrent-m_vidsFirst) / m_fps * 1000.0)); }
	long	vidsGetFrame () { return m_vidsCurrent; }

	int	vidsGetNumFrames () { return m_vidsLast-m_vidsFirst+1; }

		// frame=-1 means frame=m_vidsCurrent
	BOOL	vidsIsKey (long frame = -1);

		// Will always decode current frame
	void	vidsResetDraw () { m_vidsPrevious = -1; }

	// Information
	HDRAWDIB	m_hdd;
	HDC		m_hdc;

	void	vidsResetSkipCount () { m_play_fskipped = 0; }
	int	vidsFramesSkipped () { return m_play_fskipped; }

protected:
	long	m_timePlayStart, m_timePlayStartPos;

	int	m_play_fprev;   // to help us calculate ...
	int	m_play_fskipped;// frames skipped since last play

private:
	// Internal functions/vars
	BOOL	vidsSync ();
	void	vidsCatchup ();

	long	m_vidsCurrent;  // attempted frame to draw
	long	m_vidsPrevious; // last successfully decoded frame

	long	m_vidsPrevKey, m_vidsNextKey;

	long	m_vidsFirst, m_vidsLast;

	unsigned char * m_pvBuf; // for optimization - storage for returning frame bits
	int	m_cbvBuf;          // count bytes of above buffer
   RECT  m_Rect;           // bounding rectangle for transparency

// Audio
	// Operation
public:
	long	audsWaveOpen (HWND hwnd);
	long	audsWaveClose ();
	
	long	audsWavePlay (long fStart, long fEnd, BOOL bFrameSamp);
	long	audsWaveStop ();
	long	audsWavePause ();
	long	audsWaveRestart ();

	long	audsGetTime ();        // postion in ms since audsWavePlay ()
	long	audsFillBuf (int nLen);
	long	audsOutBuf ();
	long	audsDoneBuf ();

	// Information
	long	audsTimeToSample (long lTime);

protected:
	HWAVEOUT m_hWaveOut;
	
	long	m_timeAudioStart;

	long	m_audsFirst, m_audsLast; // first and last audio frame
	long	m_audsSkew; // # frames skew

	long	m_sampsPerSec;
	long	m_bytesPerSec;
	long	m_sampSize;      // size (bytes) of one audio sample
	long	m_sampsPerFrame; // # samples in one frame (1/fps sec)

private:
	long	m_audsCurrent; // current frame of audio during playback

	WAVEHDR	* m_audsBuf [MAX_AUDIOBUFS]; // data follows
	int	m_iaudsFreeBuf; // points to next free buffer
	int	m_iaudsPlayBuf; // points to next buffer to play
	int	m_naudsBufsOut; // number to buffers currently out
};

#endif // _AVIMOVIE_H_
/************************/

/************************/
// scale.h
//

// This code and information is provided "as is" without warranty of
// any kind, either expressed or implied, including but not limited to
// the implied warranties of merchantability and/or fitness for a
// particular purpose.

// Copyright (C) 1995 Intel Corporation.  All rights reserved.
//

typedef struct tagPROCESSOR
{
	char text [128]; // text description
	long mhz;        // mhz in terms of Pentium(R)
}
PROCESSOR;

BOOL setProcessor (PROCESSOR processor_list [], int nlen);
extern int giActualProcessor;

#define ABS_(x) (x<0 ? (-(x)) : (x))
/************************/

/************************/
// movie.h
//

// This code and information is provided "as is" without warranty of
// any kind, either expressed or implied, including but not limited to
// the implied warranties of merchantability and/or fitness for a
// particular purpose.

// Copyright (C) 1995 Intel Corporation.  All rights reserved.
//

// defines
#define ID_FILE_OPEN                    40001
#define ID_FILE_CLOSE                   40002
#define ID_MOVIE_PLAY                   40003
#define ID_MOVIE_STOP                   40004
#define ID_MOVIE_REWIND                 40006
#define ID_MOVIE_PLAYBAR                40007
#define ID_OPTIONS_BITDEPTH_CLUT8       40008
#define ID_OPTIONS_BITDEPTH_RGB16       40009
#define ID_OPTIONS_BITDEPTH_RGB16_555   40010
#define ID_OPTIONS_BITDEPTH_RGB16_565   40011
#define ID_OPTIONS_BITDEPTH_RGB24       40012
#define ID_OPTIONS_BITDEPTH_RGB32       40013
#define ID_OPTIONS_RESOLUTION_NATIVE    40014
#define ID_OPTIONS_RESOLUTION_ZOOMBY2   40015
#define ID_OPTIONS_RESOLUTION_OTHER     40017
#define ID_OPTIONS_RESOLUTION_ZOOMBY2ALT 40017
#define ID_OPTIONS_INDEOVIDEOR4_COLORCONTROLS 40018
#define ID_OPTIONS_INDEOVIDEOR4_ACCESSKEY 40019
#define ID_OPTIONS_INDEOVIDEOR4_SCALABILITY 40020
#define ID_MOVIE_LOOP                   40021
#define ID_MOVIE_STATISTICS             40023
#define ID_MOVIE_PAUSE                  40024
#define ID_MOVIE_REDRAW                 40025
#define ID_MOVIE_STEPBACK               40026
#define ID_MOVIE_STEPFORWARD            40027
#define ID_MOVIE_PLAYPAUSE              40029
#define ID_MOVIE_INFO                   40031
#define ID_MOVIE_PAGEBACK               40032
#define ID_MOVIE_PAGEFORWARD            40033
#define ID_MOVIE_SECBACK                40034
#define ID_MOVIE_SECFORWARD             40035
#define ID_MOVIE_SEEKBAR                40037
#define ID_OPTIONS_PALETTE_NATIVE       40043
#define ID_OPTIONS_PALETTE_CLIPBOARD    40044
#define ID_OPTIONS_PALETTE_GRAY         40045
#define ID_OPTIONS_INDEOVIDEOR4_TRANSPARENCY_SETBACKGROUND 40046
#define ID_OPTIONS_PALETTE_LOAD         40047
#define ID_OPTIONS_PALETTE_FILE         40047
#define ID_OPTIONS_INDEOVIDEOR4_CONTROLS 40048
#define ID_OPTIONS_INDEOVIDEOR4_SETBACKGROUND 40049
#define ID_OPTIONS_INDEOVIDEOR4_CUSTOM  40050
#define ID_OPTIONS_PALETTE_ACTIVE       40051

// Globals

// Movie instance
extern CAviMovie * gpMovie;

// Critical Section gPlayKey and var gbPlay for synchronization
extern CRITICAL_SECTION gPlayKey;
extern BOOL gbPlay;
	
// Stores information for file properties
typedef struct tagKFILEINFO
{
	FOURCC fcc;
	// General
	char szFileName [128];
	char szMediaLen [128];
	char szAudioFmt [128];
	char szVideoRes [128];
	char szVideoNFm [128];
	char szVideoFPS [128];
	char szVideoFmt [128];
	char szDataRate [128];
} KFILEINFO;


// Commands

// Thread Proc

void MovieThreadProc (void * pParm);

// Init/Term

void MovieInitialize (HWND);
void MovieTerminate (HWND);

// File	ops

BOOL MovieFileOpen (HWND, LPSTR);
void MovieFileClose (HWND);

// Movie ops

void MoviePlay (HWND);
void MovieStop (HWND);
void MoviePause (HWND);

void MovieSeek (HWND, long);
void MovieSeekCurrent (HWND, long);
void MovieSeekPercent (HWND, int);
void MovieSeekSec (HWND, int);

void MovieToggleLoop (HWND);

void MovieRedraw (HWND);      // ID_MOVE_REDRAW

void MovieGetInfo (HWND, char *, KFILEINFO *);

// Options

void MovieSetOptionsBitdepth (HWND, int);
void MovieSetOptionsResolution (HWND hwnd, int id, int xres = 0, int yres = 0);
void MovieSetOptionsPalette (HWND, int);
long MovieSetOptions8BitDither( HWND hwnd, int iDither, int iFirst, int iLast );
long MovieGetOptions8BitDither( void );

// Indeo(R) Video Interactive Options

// Transparency background
void MovieSetBackground(HWND hwnd, char* file = NULL);
long MovieLoadPalette(HWND hwnd, LOGPALETTE* pLogPal);
BOOL MoviePointInImage(int xpos, int ypos );
void MovieSetImagePos(int xpos, int ypos);

// Brightness, Saturation, Contrast
void MovieGetOptionsBSC (HWND, long *, long *, long *, BOOL);
void MovieSetOptionsBSC (HWND, long, long, long, BOOL);

// Scalability
void MovieGetOptionsScalability (HWND, int *, BOOL);
void MovieSetOptionsScalability (HWND, int, BOOL);
void MovieSetOptionsAccessKey (HWND hwnd, DWORD dwKey);

extern DWORD gIdle;
void MovieSetgIdle (int, PROCESSOR []);
long MovieGetMSToProcessor (long, PROCESSOR [], int);
long MovieGetProcessorToMS (int, PROCESSOR [], int);

// Other messages

void MoviePaint (HWND, HDC, PAINTSTRUCT *); // WM_PAINT

void MoviePaletteChanged (HWND, HWND);

void MovieAudioMsg (HWND, UINT); // MM_WOM_ msgs

int MovieGetHandle();
/************************/
